package android.framework.binding;

import java.util.ArrayList;
import java.util.List;

public class MultiBindingAdapter<T> implements IObserver<T> {

	private List<IObserver<T>> observers = new ArrayList<IObserver<T>>();
	
	public MultiBindingAdapter(){
		
	}
	
	public MultiBindingAdapter(List<IObserver<T>> observers){
		this.observers = observers;
	}
	
	public void addObserver(IObserver<T> observer){
		if(!observers.contains(observer)){
			observers.add(observer);
		}
	}
	
	public boolean removeObserver(IObserver<T> observer){
		if(observers.contains(observer)){
			return observers.remove(observer);
		}
		return false;
	}
	
	public void clear(){
		observers.clear();
	}
	
	public boolean notifyChanges(T value, long actionId) {
		boolean result = false;
		for (IObserver<T> observer : observers) {
			result |= observer.notifyChanges(value, actionId);
		}
		return result;
	}

}
